package com.mathassistant.client.view;

import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLTable;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.mathassistant.client.presenter.TheoryPresenter;

public class TheoryView extends Composite implements TheoryPresenter.Display{

	private static TheoryViewUiBinder uiBinder = GWT
			.create(TheoryViewUiBinder.class);
	@UiField FlexTable listLesson;
	@UiField HTML contentLesson;

	interface TheoryViewUiBinder extends UiBinder<Widget, TheoryView> {
	}

	public TheoryView() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	@Override
	public HasClickHandlers getListTheory() {
		// TODO Auto-generated method stub
		return listLesson;
	}

	@Override
	public int getRowSelected(ClickEvent event) {
		// TODO Auto-generated method stub
		int rowSelected = -1;
		HTMLTable.Cell cell = listLesson.getCellForEvent(event);
		if(cell != null){
			rowSelected = cell.getRowIndex();
		}
		return rowSelected;
	}

	@Override
	public void setListTitle(List<String> titleLessons) {
		// TODO Auto-generated method stub
		listLesson.clear();
		if(titleLessons == null){
			return;
		}
		for(int i = 0; i < titleLessons.size(); i++){
			listLesson.setText(i, 0, titleLessons.get(i));
			listLesson.getCellFormatter().addStyleName(i, 0, "titleTheory");
		}
	}

	@Override
	public void setContentLesson(String content) {
		// TODO Auto-generated method stub
		contentLesson.setHTML(content);
	}

}
